<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Jsl Core Functions Test Suite</title>
<script language="javascript" src="../jsunit/app/jsUnitCore.js"></script>
<script language="javascript" src="../src/core.js"></script>
</head>
<body>
<div id="testBox"></div>
<script language="javascript">
// testing Jsl.isObject function
function testIsValidIsObject() {
	assert(Jsl.isObject({}));
};
function testIsNotValidIsObject() {
	assert(!Jsl.isObject(1));
	assert(!Jsl.isObject('object'));
	assert(!Jsl.isObject(new Date()));
	assert(!Jsl.isObject(true));
	assert(!Jsl.isObject([]));
	assert(!Jsl.isObject(document.getElementById( 'testBox')));
	assert(!Jsl.isObject(/[a-z]+/));
	assert(!Jsl.isObject(Jsl.fn.empty));
};

// testing Jsl.isElement function
function testIsValidIsElement() {
	assert(Jsl.isElement(document.getElementById( 'testBox')));
};
function testIsNotValidIsElement() {
	assert(!Jsl.isElement({}));
	assert(!Jsl.isElement(Object.prototype));
	assert(!Jsl.isElement(true));
	assert(!Jsl.isElement(1));
	assert(!Jsl.isElement('object'));
	assert(!Jsl.isElement(new Date()));
	assert(!Jsl.isElement([]));
	assert(!Jsl.isElement(/[a-z]+/));
	assert(!Jsl.isElement(Jsl.fn.empty));
};

// testing Jsl.isArray function
function testIsValidIsArray() {
	assert(Jsl.isArray([]));
};
function testIsNotValidIsArray() {
	assert(!Jsl.isArray({}));
	assert(!Jsl.isArray(Object.prototype));
	assert(!Jsl.isArray(true));
	assert(!Jsl.isArray(1));
	assert(!Jsl.isArray('object'));
	assert(!Jsl.isArray(new Date()));
	assert(!Jsl.isArray(document.getElementById( 'testBox')));
	assert(!Jsl.isArray(/[a-z]+/));
	assert(!Jsl.isArray(Jsl.fn.empty));
};

// testing Jsl.isRegExp function
function testIsValidIsRegExp() {
	assert(Jsl.isRegExp(/[a-z]+/));
	assert(Jsl.isRegExp(new RegExp));
};
function testIsNotValidIsRegExp() {
	assert(!Jsl.isRegExp({}));
	assert(!Jsl.isRegExp(Object.prototype));
	assert(!Jsl.isRegExp(true));
	assert(!Jsl.isRegExp(1));
	assert(!Jsl.isRegExp('object'));
	assert(!Jsl.isRegExp(new Date()));
	assert(!Jsl.isRegExp(document.getElementById( 'testBox')));
	assert(!Jsl.isRegExp(Jsl.fn.empty));
};

// testing Jsl.isFunction function
function testIsValidIsFunction() {
	assert(Jsl.isFunction(Jsl.fn.empty));
	assert(Jsl.isFunction(function(){}));
};
function testIsNotValidIsFunction() {
	assert(!Jsl.isFunction({}));
	assert(!Jsl.isFunction(Object.prototype));
	assert(!Jsl.isFunction(true));
	assert(!Jsl.isFunction(1));
	assert(!Jsl.isFunction('object'));
	assert(!Jsl.isFunction(new Date()));
	assert(!Jsl.isFunction(document.getElementById( 'testBox')));
};

// testing Jsl.isString function
function testIsValidIsString() {
	assert(Jsl.isString(""));
};
function testIsNotValidIsString() {
	assert(!Jsl.isString({}));
	assert(!Jsl.isString(Object.prototype));
	assert(!Jsl.isString(true));
	assert(!Jsl.isString(1));
	assert(!Jsl.isString(new Date()));
	assert(!Jsl.isString(document.getElementById( 'testBox')));
	assert(!Jsl.isString(Jsl.fn.empty));
};

// testing Jsl.isNumeric function
function testIsValidIsNumeric() {
	assert(Jsl.isNumeric("123"));
	assert(Jsl.isNumeric(123));
	assert(Jsl.isNumeric("123.90"));
	assert(Jsl.isNumeric(123.90));
};
function testIsNotValidIsNumeric() {
	assert(!Jsl.isNumeric({}));
	assert(!Jsl.isNumeric("123dfg"));
	assert(!Jsl.isNumeric("123.897.09"));
	assert(!Jsl.isNumeric(Object.prototype));
	assert(!Jsl.isNumeric(true));
	assert(!Jsl.isNumeric(new Date()));
	assert(!Jsl.isNumeric(document.getElementById( 'testBox')));
	assert(!Jsl.isNumeric(Jsl.fn.empty));
};

// testing Jsl.isNumber function
function testIsValidIsNumber() {
	assert(Jsl.isNumber(123));
	assert(Jsl.isNumber(123.90));
};
function testIsNotValidIsNumber() {
	assert(!Jsl.isNumber({}));
	assert(!Jsl.isNumber("123"));
	assert(!Jsl.isNumber("123.89"));
	assert(!Jsl.isNumber(Object.prototype));
	assert(!Jsl.isNumber(true));
	assert(!Jsl.isNumber(new Date()));
	assert(!Jsl.isNumber(document.getElementById( 'testBox')));
	assert(!Jsl.isNumber(Jsl.fn.empty));
};

// testing Jsl.isDefined function
function testIsValidIsDefined() {
	assert(Jsl.isDefined(Jsl));
	assert(Jsl.isDefined(null));
};
function testIsNotValidIsDefined() {
	assert(!Jsl.isDefined(window.__SOME_UNDEFINED_VAR__));
	assert(!Jsl.isDefined(undefined));
};

// testing Jsl.isNull function
function testIsValidIsNull() {
	assert(Jsl.isNull(null));
};
function testIsNotValidIsNull() {
	assert(!Jsl.isNull(window.__SOME_UNDEFINED_VAR__));
	assert(!Jsl.isNull(undefined));
	assert(!Jsl.isNull({}));
	assert(!Jsl.isNull("123"));
	assert(!Jsl.isNull("123.89"));
	assert(!Jsl.isNull(Object.prototype));
	assert(!Jsl.isNull(true));
	assert(!Jsl.isNull(false));
	assert(!Jsl.isNull(new Date()));
	assert(!Jsl.isNull(document.getElementById( 'testBox')));
	assert(!Jsl.isNull(Jsl.fn.empty));
};

// testing Jsl.isDate function
function testIsValidIsDate() {
	assert(Jsl.isDate(new Date()));
};
function testIsNotValidIsDate() {
	assert(!Jsl.isDate(undefined));
	assert(!Jsl.isDate({}));
	assert(!Jsl.isDate("123"));
	assert(!Jsl.isDate("123.89"));
	assert(!Jsl.isDate(Object.prototype));
	assert(!Jsl.isDate(true));
	assert(!Jsl.isDate(false));
	assert(!Jsl.isDate(document.getElementById( 'testBox')));
	assert(!Jsl.isDate(Jsl.fn.empty));
};

// testing Jsl.isBoolean function
function testIsValidIsBoolean() {
	assert(Jsl.isBoolean(true));
	assert(Jsl.isBoolean(false));
};
function testIsNotValidIsBoolean() {
	assert(!Jsl.isBoolean(undefined));
	assert(!Jsl.isBoolean(null));
	assert(!Jsl.isBoolean({}));
	assert(!Jsl.isBoolean("123"));
	assert(!Jsl.isBoolean("123.89"));
	assert(!Jsl.isBoolean(Object.prototype));
	assert(!Jsl.isBoolean(document.getElementById( 'testBox')));
	assert(!Jsl.isBoolean(Jsl.fn.empty));
};

// testing Jsl.encode function
function testJsonEncodeValid() {
	assertEquals( "Stringifying Object to JSON string", '{"a":"b","c":"d"}', Jsl.encode({ a : 'b', c : 'd'}));
	assertEquals( "Stringifying Array to JSON string", '[1,2,3,4,5]', Jsl.encode( [1,2,3,4,5]));
	assertEquals( "Stringifying Null to JSON string", 'null', Jsl.encode(null));
	assertEquals( "Stringifying Undefined to JSON string", 'null', Jsl.encode(undefined));
	assertEquals( "Stringifying DOM element to JSON string", '{}', Jsl.encode(document.getElementById('testBox')));
	assertEquals( "Stringifying Boolean TRUE to JSON string", 'true', Jsl.encode(true));
	assertEquals( "Stringifying Boolean FALSE to JSON string", 'false', Jsl.encode(false));
	assertEquals( "Stringifying String to JSON string", '"hello, world"', Jsl.encode( "hello, world"));
	assertEquals( "Stringifying Number integer to JSON string", '123', Jsl.encode( 123));
	assertEquals( "Stringifying Number float to JSON string", '123.9', Jsl.encode( 123.90));
};

// testing Jsl.decode function
function testJsonDecodeValid() {
	assert(Jsl.isBoolean( Jsl.decode( 'true')));
	assert(Jsl.isNumber( Jsl.decode( '123.90')));
	assert(Jsl.isObject( Jsl.decode( '{"a":"b","c":"d"}')));
	assert(Jsl.isArray( Jsl.decode( '[1,2,3,4,5]')));
	assert(Jsl.isNull( Jsl.decode( 'null')));
};

// testing String.repeat method
function testStringRepeat() {
	assertEquals( "String repeat test 1", "aa", "aa".repeat( 1));
	assertEquals( "String repeat test 2", "aaaa", "aa".repeat( 2));
	assertEquals( "String repeat test 10", "aaaaaaaaaa", "a".repeat( 10));
	assertEquals( "String repeat test without args", "aa", "aa".repeat());
	assertEquals( "String repeat test -5", "aa", "aa".repeat( -5));
};

// testing Array.inArray method
function testInArray() {
	assert([1,2,3,4,5,6].inArray( 3));
	assert(![1,2,3,4,5,6].inArray( 7));
	assert([1,2,3,window,document,5].inArray(document));
	assert(![1,2,3].inArray(window));
	var a = [3,4,5];
	assert([1,2,a,6].inArray(a));
};

//testing Array.merge method
function testArrayMerge() {
	assertArrayEquals( "Merging two arrays", [1,2,3,4], [1,2].merge( [3,4]));
	assertArrayEquals( "Merging three arrays", [1,2,3,4,5,6], [1,2].merge( [3,4], [5,6]));
	assertArrayEquals( "Merging four arrays", [1,2,3,4,5,6,7], [1,2].merge( [3,4], [5,6], [7]));
};

// testing Array.unique method
function testArrayUnique() {
	assertArrayEquals( "Unique array test", [1,2,3,4,5,6,7], [1,2,3,4,5,5,5,6,6,7,3,2,1].unique());
};

// testing Number.pad method
function testNumberPad() {
	assertEquals( "Leading zero no args", "09", (9).pad());
	assertEquals( "Leading zero num = 3", "0009", (9).pad( 3));
	assertEquals( "Leading zero num = 1, base = 10", "99", (99).pad( 1, 10));
	assertEquals( "Leading zero num = 2, base = 100", "0099", (99).pad( 2, 100));
};
</script>
</body>
</html>